#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
#define ll long long
int n,m,cnt;
const int maxn = 1e5+10;
int ans[maxn];
void solve(int n,int m,int pos)
{
	if(n==0||m==0) 
	{
		cnt = pos;
		return ;
	}
	if(n<m) 
	{
		int t = n;
		n = m;
		m = t;
	}
	for(int i = 0;i<m;i++)
	{
		ans[pos++] = m;
	}
	solve(n-m,m,pos);
}
int main(){
	int t;
	cin>>t;
	while(t--){
		scanf("%d%d",&n,&m);
		if(n==m){
			cout<<n<<endl;
			for(int i=1;i<=n-1;i++) cout<<n<<" ";
			cout<<n<<endl;
		}
		else{
			solve(n,m,0);
			//9 2
		//2 2 2 2 2 2 2 2 1 1
			//9 1
		//	1 1 1 1 1 1 1 1 1 	
			int ans1=min(n,m);
			int ans2=max(n,m)%min(n,m)%min(n,m);
			int cntans1 = ans1;
			printf("%d\n",cnt);
			printf("%d",ans[0]);
			for(int i = 1;i<cnt;i++)
			{
				printf(" %d",ans[i]);
			}
			printf("\n");
		}
	}
}


